var app = getApp();
Page({
  data: {
    
  },
  onLoad: function (e) {
    var that = this;
    that.setData({
      sharedata: app.globalData.sharedata
    });
    console.log(that.data.sharedata);
    if (!that.data.sharedata.shareUrl){
      return;
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
      time: 100000
    })
    wx.downloadFile({
      url: that.data.sharedata.shareUrl,
      success: function (res) {
        console.log(res);
        that.setData({
          tempFilePathShow:res.tempFilePath
        })
        wx.hideLoading();
      }
    })
    console.log(that.data.sharedata);
  },
  onShareAppMessage: function () {
    var that = this;
    var title = this.data.sharedata.shareTitle;
    var shareInfo = app.globalData.shareInfo;
    title = shareInfo.shareTitle ? shareInfo.shareTitle : title;
    var cover = shareInfo.shareCover ? shareInfo.shareCover : '';
    app.getPoint(that);
    return {
      title: title,
      imageUrl: cover,
      path: '/pages/singlePage/singlePage'
    }
  },
  saveImage:function(){
    var that = this;
    var imgpath = this.data.sharedata.shareUrl;
    var tempFilePathShow = this.data.tempFilePathShow;
    if (imgpath.length<=0){
      app.errorTip(that, "海报图片不存在", 2000);
      return;
    }
    wx.showLoading({
      title: '正在保存',
      mask: true,
      time: 100000
    })
    wx.saveImageToPhotosAlbum({
      filePath: tempFilePathShow,
      success(res) {
        console.log(res);
        app.errorTip(that, "图片保存成功", 2000);
      },
      fail(f) {
        app.errorTip(that, "图片保存失败", 2000);
      },
      complete() {
        wx.hideLoading();
      }
    })
  }
})